#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/27 11:49
# @Author: hekang
# @Email: 591785757@qq.com
# @File：works_page.py
from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage


class WorksPage(BasePage):
    '''定位器'''
    image_video_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTvSetName\"]")
    screenshots_locator = (
        By.ANDROID_UIAUTOMATOR, "new UiSelector().className(\"android.widget.TextView\").textContains(\"Screenshots\")"
                                ".resourceId(\"com.gfeng.daydaycook:id/name\")")
    all_videos_locator = (
        By.ANDROID_UIAUTOMATOR, "new UiSelector().className(\"android.widget.TextView\").textContains(\"所有视频\")"
                                ".resourceId(\"com.gfeng.daydaycook:id/name\")")
    video_locator = (
        By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/mRecyclerView\"]"
                  "/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.ImageView[1]")
    video_next_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/nextTv\"]")
    video_cover_locator = (
        By.XPATH, "//android.widget.ImageView[@resource-id=\"com.gfeng.daydaycook:id/image_imageview\"]")
    select_video_cover_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_draft_save\"]")
    click_select_cover_locator = (
        By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/thumbRv\"]"
                  "/android.widget.RelativeLayout[6]/android.widget.ImageView[1]")
    right_locator = (
        By.XPATH, "//android.widget.ImageView[@resource-id=\"com.gfeng.daydaycook:id/nextTv\"]")
    picture1_locator = (
        By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/mRecyclerView\"]"
                  "/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.TextView[1]")
    picture2_locator = (
        By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/mRecyclerView\"]"
                  "/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.TextView[1]")
    picture3_locator = (
        By.XPATH, "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/mRecyclerView\"]"
                  "/android.widget.FrameLayout[3]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.TextView[1]")
    preview_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mPreview\"]")
    next1_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.TextView[2]")
    ratio_locator = (
        By.XPATH, "//android.widget.RadioButton[@resource-id=\"com.gfeng.daydaycook:id/rb_crop_34\"]")
    next2_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/mTvNext\"]")
    works_send_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.RelativeLayout[1]/android.widget.TextView[1]")
    works_title_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.ScrollView[1]/android.widget.RelativeLayout[1]/android.support.v7.widget.RecyclerView[1]"
                  "/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]"
                  "/android.widget.EditText[1]")
    works_content_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.ScrollView[1]/android.widget.RelativeLayout[1]/android.support.v7.widget.RecyclerView[1]"
                  "/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]"
                  "/android.widget.EditText[2]")

    # 选择图片文件夹
    def image_video(self):
        self.find_element(self.image_video_locator).click()

    # 选择截屏文件
    def screenshots(self):
        self.find_element(self.screenshots_locator).click()

    # 选择所有视频文件
    def all_videos(self):
        self.find_element(self.all_videos_locator).click()

    # 选择视频
    def video(self):
        self.find_element(self.video_locator).click()

    # 视频选中后下一步
    def video_next(self):
        self.find_element(self.video_next_locator).click()

    # 进入视频封面选择
    def video_cover(self):
        self.find_element(self.video_cover_locator).click()

    # 选择一个视频封面
    def select_video_cover(self):
        self.find_element(self.select_video_cover_locator).click()

    # 确定封面
    def right(self):
        self.find_element(self.right_locator).click()

    # 选择图片1
    def picture1(self):
        self.find_element(self.picture1_locator).click()

    # 选择图片2
    def picture2(self):
        self.find_element(self.picture2_locator).click()

    # 选择图片3
    def picture3(self):
        self.find_element(self.picture3_locator).click()

    # 图片预览
    def preview(self):
        self.find_element(self.preview_locator).click()

    # 图片选中后下一步
    def next1(self):
        self.find_element(self.next1_locator).click()

    # 改变图片比例
    def radio(self):
        self.find_element(self.ratio_locator).click()

    # 调整完图片后下一步
    def next2(self):
        self.find_element(self.next2_locator).click()

    # 写入标题
    def works_title(self, title):
        self.find_element(self.works_title_locator).send_keys(title)

    # 写入内容
    def works_content(self, content):
        self.find_element(self.works_content_locator).send_keys(content)

    # 点击发布
    def works_send(self):
        self.find_element(self.works_send_locator).click()
